﻿using System;
using System.Linq;
using System.Web.Mvc;
using System.Web.Routing;
using Core.BOL;
using Core.DAL;
using Core.Extentions;

namespace ScoutNET.Controllers
{
    public class SectionController : ApplicationController
    {
        private NewsRepository nr = new NewsRepository();
        private CalendarRepository cr = new CalendarRepository();
        private SectionRepository sr = new SectionRepository();
        private ImagesRepository ir = new ImagesRepository();

        public ActionResult Index(string systemName)
        {
            tSite_Section section = sr.GetSectionsBySystemName(systemName);

            ViewData["PageTitle"] = Resources.Section_Index_Title.Replace("[SECTION]", section.Sections);
            ViewData["PageDescription"] = Resources.Home_Index_Description;

            string[] saBreadcrumb = new String[2];
            saBreadcrumb[0] = HtmlHelper.GenerateLink(this.ControllerContext.RequestContext, RouteTable.Routes, Resources.Master_Breadcrumb_Home, "Default", "Index", "Home", null, null);
            saBreadcrumb[1] = section.Section.UppercaseFirst();
            ViewData["Breadcrumb"] = saBreadcrumb;

            sp_Site_GetRandomImageBySystemNameResult i = ir.GetRandomImageBySystemName(1, systemName).Take(1).SingleOrDefault();

            ViewData["RandomImg"] = i;
            ViewData["News"] = nr.GetNewsBySectionName(systemName, 0, 4);
            ViewData["LatestEvents"] = cr.GetNextEventsBySystemName(systemName, 10);
            ViewData["SectionsName"] = section.Sections;
            ViewData["SectionName"] = section.Section;

            return View();
        }
    }
}